/**
 * 
 */
package com.surelution.core;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.ObjectOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @author <a href="mailto:guangzong.syu@gmail.com">Guangzong</a>
 *
 */
public class Test {
	
	public static String DATE_PATTERN = "yyyyMMdd";

	public static void main(String[] args) throws Exception{
		
		SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
		
		Scanner scanner = new Scanner(System.in);
//		System.out.println("Company name:");
		String companyName = "中国石油台州销售分公司";
		
//		System.out.println(companyName);
		
		System.out.print("from(");
		System.out.print(DATE_PATTERN);
		System.out.println("):");
		Date from = sdf.parse(scanner.nextLine());

		System.out.print("to(");
		System.out.print(DATE_PATTERN);
		System.out.println("):");
		
		Date to = sdf.parse(scanner.nextLine());

		Set<String> wands = new HashSet<String>();
		
		Set<String> poiSns = new HashSet<String>();
		
		System.out.println("File path:");
		
		String filePath = "/Users/johnny/Google Drive/patro-sn/" + scanner.nextLine();
		String wandPath = filePath + "/wandsn.txt";
		BufferedReader br = new BufferedReader(new FileReader(new File(wandPath)));
		String line = br.readLine();
		while(line != null) {
			wands.add(line);
			line = br.readLine();
		}
		br.close();

		String poiPath = filePath + "/poisn.txt";
		BufferedReader br2 = new BufferedReader(new FileReader(new File(poiPath)));
		line = br2.readLine();
		while(line != null) {
			poiSns.add(line.substring(0,4));
			line = br2.readLine();
		}
		br2.close();
		
		SystemInfo info = new SystemInfo(companyName, from, to, wands, poiSns);
		
		System.out.println(info.getFrom());
		System.out.println(info.getTo());
		File file = new File(filePath + "/sn.key");
		FileOutputStream fos = new FileOutputStream(file);
		ObjectOutputStream oos = new ObjectOutputStream(fos);
		oos.writeObject(info);
		oos.close();
		fos.close();
	}
}
